<script setup lang="ts">
import { ref } from "vue";
import { useRouter } from "vue-router";
import { Setting, Shop, User, Bicycle } from "@element-plus/icons-vue";

const router = useRouter();

const selectRole = (role: string) => {
  console.log(`选择角色: ${role}`);
  if (role === "merchant") {
    console.log("尝试跳转到商家登录页面");
    router.push("/merchant/login");
  } else if (role === "admin") {
    console.log("尝试跳转到管理员登录页面");
    router.push("/admin/login");
  } else if (role === "customer") {
    console.log("尝试跳转到顾客登录页面");
    router.push("/customer/login");
  } else if (role === "rider") {
    console.log("尝试跳转到骑手登录页面");
    router.push("/rider/login");
  }
};
</script>

<template>
  <div class="role-select-container">
    <div class="tech-bg"></div>
    <div class="role-select-content">
      <div class="logo">
        <img src="/logo.png" alt="饱了么" class="logo-image" />
        <h1>
          饱了么
          <span class="en-title">Baoleme</span>
        </h1>
        <p>校园外卖平台管理系统</p>
      </div>

      <div class="role-cards">
        <div class="role-card" @click="selectRole('customer')">
          <el-icon :size="64"><User /></el-icon>
          <h2>
            顾客入口
            <span class="en-role">Customer</span>
          </h2>
          <p>浏览商家和下单</p>
        </div>

        <div class="role-card" @click="selectRole('merchant')">
          <el-icon :size="64"><Shop /></el-icon>
          <h2>
            商家入口
            <span class="en-role">Merchant</span>
          </h2>
          <p>管理店铺、商品和订单</p>
        </div>

        <div class="role-card" @click="selectRole('rider')">
          <el-icon :size="64"><Bicycle /></el-icon>
          <h2>
            骑手入口
            <span class="en-role">Rider</span>
          </h2>
          <p>接单配送服务</p>
        </div>

        <div class="role-card" @click="selectRole('admin')">
          <el-icon :size="64"><Setting /></el-icon>
          <h2>
            管理员入口
            <span class="en-role">Admin</span>
          </h2>
          <p>系统管理与审核</p>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
@import url("https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@500&display=swap");

html,
body,
#app {
  height: 100vh;
  width: 100vw;
  margin: 0;
  padding: 0;
  overflow: hidden !important;
  font-family: "Noto Serif SC", "阿里巴巴普惠体", "思源宋体", "微软雅黑",
    "Microsoft YaHei", Arial, sans-serif;
}

.role-select-container {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  height: 100vh;
  width: 100vw;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  background: linear-gradient(135deg, #ffe082 0%, #ffd54f 100%);
  color: #7c4a03;
  font-family: "Noto Serif SC", "阿里巴巴普惠体", "思源宋体", "微软雅黑",
    "Microsoft YaHei", Arial, sans-serif;
}

.tech-bg {
  position: absolute;
  z-index: 0;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  height: 100vh;
  background: linear-gradient(
      rgba(255, 224, 130, 0.82),
      rgba(255, 213, 79, 0.82)
    ),
    url("https://images.pexels.com/photos/70497/pexels-photo-70497.jpeg?auto=compress&w=900&q=80")
      center center/cover no-repeat;
  pointer-events: none;
}
.tech-bg::before,
.tech-bg::after {
  display: none;
}

.role-select-content {
  z-index: 1;
  text-align: center;
  background: rgba(255, 236, 179, 0.92);
  border-radius: 24px;
  box-shadow: 0 8px 32px 0 rgba(255, 152, 0, 0.18);
  padding: 3rem 4rem 2.5rem 4rem;
  min-width: 760px;
  min-height: 500px;
  max-height: 90vh;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* 移动端适配 */
@media (max-width: 768px) {
  .role-select-content {
    min-width: 90%;
    max-width: 500px;
    max-height: 85vh;
    padding: 2rem 2rem 1.5rem 2rem;
    min-height: 400px;
    border-radius: 20px;
    margin: 1rem;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
  }
}

@media (max-width: 480px) {
  .role-select-content {
    min-width: 95%;
    max-width: 380px;
    max-height: 90vh;
    padding: 1.5rem 1rem 1rem 1rem;
    min-height: 350px;
    border-radius: 16px;
    margin: 0.5rem;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
  }
}

.logo {
  margin-bottom: 3rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

@media (max-width: 480px) {
  .logo {
    margin-bottom: 2rem;
  }
}

.logo-image {
  width: 80px;
  height: 80px;
  margin-bottom: 1rem;
}

@media (max-width: 480px) {
  .logo-image {
    width: 60px;
    height: 60px;
    margin-bottom: 0.75rem;
  }
}

.logo h1 {
  font-size: 3.2rem;
  font-family: "Noto Serif SC", "阿里巴巴普惠体", "思源宋体", "微软雅黑",
    "Microsoft YaHei", Arial, sans-serif;
  letter-spacing: 0.08em;
  margin-bottom: 0.5rem;
  color: #d2691e;
  text-shadow: 0 2px 16px #ffe08288, 0 1px 0 #fffbe7;
  display: flex;
  flex-direction: column;
  align-items: center;
}

@media (max-width: 768px) {
  .logo h1 {
    font-size: 2.5rem;
  }
}

@media (max-width: 480px) {
  .logo h1 {
    font-size: 2rem;
    letter-spacing: 0.05em;
  }
}

.logo .en-title {
  font-size: 1.1rem;
  color: #bfa16b;
  font-family: Arial, sans-serif;
  margin-top: 0.2rem;
  letter-spacing: 0.12em;
  opacity: 0.85;
}

@media (max-width: 480px) {
  .logo .en-title {
    font-size: 0.9rem;
    letter-spacing: 0.08em;
  }
}

.logo p {
  font-size: 1.1rem;
  color: #a05a1c;
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.role-cards {
  display: flex;
  gap: 2rem;
  justify-content: center;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

@media (max-width: 768px) {
  .role-cards {
    gap: 1.5rem;
    margin-top: 1rem;
  }
}

@media (max-width: 480px) {
  .role-cards {
    gap: 1rem;
    margin-top: 1rem;
    flex-direction: column;
    align-items: center;
  }
}

.role-card {
  width: 200px;
  height: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.3s, box-shadow 0.3s;
  background: rgba(255, 243, 207, 0.96);
  border: 2px solid #ffd54f;
  border-radius: 18px;
  box-shadow: 0 4px 24px 0 #ffd54f66;
  position: relative;
  overflow: hidden;
}

@media (max-width: 768px) {
  .role-card {
    width: 180px;
    height: 180px;
    border-radius: 16px;
  }
}

@media (max-width: 480px) {
  .role-card {
    width: 160px;
    height: 160px;
    border-radius: 14px;
  }
}
.role-card:hover {
  transform: translateY(-12px) scale(1.04);
  box-shadow: 0 8px 32px 0 #ffd54f99;
  border-color: #ffe082;
}

.role-card h2 {
  margin: 1rem 0 0.5rem;
  color: #a05a1c;
  font-family: "Noto Serif SC", "阿里巴巴普惠体", "思源宋体", "微软雅黑", Arial,
    sans-serif;
  font-size: 1.4rem;
  letter-spacing: 0.06em;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.role-card .en-role {
  font-size: 1rem;
  color: #bfa16b;
  font-family: Arial, sans-serif;
  margin-top: 0.1rem;
  opacity: 0.8;
}

.role-card p {
  color: #a05a1c;
  font-size: 1rem;
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* 滚动优化 */
@media (max-width: 768px) {
  /* 移除之前的容器滚动设置 */
}

/* 处理超小屏幕的滚动 */
@media (max-width: 480px) and (max-height: 600px) {
  .role-select-content {
    max-height: 95vh;
    min-height: auto;
    margin: 0.25rem;
  }
  
  .logo {
    margin-bottom: 1.5rem;
  }
  
  .role-cards {
    margin-top: 0.75rem;
  }
}
</style>
